require('./index.css');
let util = require('util/util.js');
let _login = require('service/loginService.js');

let login = {
    data: {
        userName: 'admin',
        password: '123'
    },
    init: function () {
        this.getLoginInfo();
    },
    //获取登录信息
    getLoginInfo: function () {
        let _this = this,
            data = this.data,
            loginBtn = document.getElementById('loginBtn'),
            userNameDOM = $.trim(util.getElementById('userName')),
            passwordDOM = $.trim(util.getElementById('password'))

        loginBtn.addEventListener('click', function () {
            let userName = userNameDOM.value,
                password = passwordDOM.value;

            _login.login({
                data: {
                    userName: userName,
                    password: password
                },
                success: function () {
                    window.location.href = './index.html';
                },
                error: function () {
                    $('.error-tips').show();
                }
            });

        })
    }
}

$(function () {
    login.init();
})